package com.xinke.juc.case03;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author：xinke
 * @Date：2025/9/30
 * @Desc: 等待多个结果
 */
@Slf4j
public class TestJoin02 {
    static int r1 = 0;
    static int r2 = 0;
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            r1 = 10;
        });
        Thread t2 = new Thread(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            r2 = 20;
        });
        long start = System.currentTimeMillis();
        t1.start();
        t2.start();
        t2.join();
        t1.join();
        long end = System.currentTimeMillis();
        log.info("r1:{} ,r2:{} ,cost:{}",r1,r2,end-start);

    }
}
